import { Injectable } from '@angular/core';
import { EntityConfig } from '../../core/entity-config.types';
import { PurchaseOrderDto } from '../../proxy/joy/erp/basic-archives/procurements';
import { DatePipe } from '@angular/common';
import { LocalizationService } from '@abp/ng.core';
import { DocumentStatus } from '../../proxy/joy/erp/basic-archives/core/document-status.enum';

@Injectable({
  providedIn: 'root'
})
export class PurchaseOrderConfigService {
  datePipe = new DatePipe('zh-CN');

  constructor(
    private localizationService: LocalizationService
  ) {}

  getConfig(): EntityConfig {
    return {
      entityType: 'Joy.Erp.BasicArchives.Procurements.PurchaseOrder',
      propertys: [
        {
          name: 'Code',
          key: 'code',
          type: 'string',
          field: (item: PurchaseOrderDto) => item.code,
          width: 200,
          show: true,
          order: 0,
          fixed: 0
        },
        {
          name: 'OrderType',
          key: 'orderType',
          type: 'string',
          field: (item: PurchaseOrderDto) => item.orderType?.displayName || '',
          width: 150,
          show: true,
          order: 1,
          fixed: 0
        },
        {
          name: 'Supplier',
          key: 'supplier',
          type: 'string',
          field: (item: PurchaseOrderDto) => item.supplier?.name || '',
          width: 200,
          show: true,
          order: 2,
          fixed: 0
        },
        {
          name: 'Operator',
          key: 'operator',
          type: 'string',
          field: (item: PurchaseOrderDto) => item.operator?.name || '',
          width: 120,
          show: true,
          order: 3,
          fixed: 0
        },
        {
          name: 'BusinessDate',
          key: 'businessDate',
          type: 'date',
          field: (item: PurchaseOrderDto) => this.datePipe.transform(item.businessDate, 'yyyy-MM-dd'),
          width: 150,
          show: true,
          order: 4,
          fixed: 0
        },
        {
          name: 'DocumentStatus',
          key: 'documentStatus',
          type: 'string',
          field: (item: PurchaseOrderDto) => this.l('BasicArchives::EnumText:Joy.Erp.BasicArchives.Core.DocumentStatus.' + DocumentStatus[item.documentStatus]),
          width: 120,
          show: true,
          order: 5,
          fixed: 0
        },
        {
          name: 'Mark',
          key: 'mark',
          type: 'string',
          field: (item: PurchaseOrderDto) => item.mark,
          width: 200,
          show: true,
          order: 6,
          fixed: 0
        },
        {
          name: 'CreationTime',
          key: 'creationTime',
          type: 'date',
          field: (item: PurchaseOrderDto) => this.datePipe.transform(item.creationTime, 'yyyy-MM-dd'),
          width: 150,
          show: true,
          order: 7,
          fixed: 0
        },
      ]
    };
  }

  private l(key: string, ...parmas: string[]): string {
    return this.localizationService.instant(key, ...parmas);
  }  
} 